package com.example.test.Dao;

import com.example.test.bean.Users;
import com.example.test.mapper.UsersMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.context.annotation.Primary;


import java.util.List;
@Primary
@Mapper
public interface UsersDao extends UsersMapper {

    //根据keyword模糊查询
    @Select("SELECT\n" +
            "\tuser_id,\n" +
            "\tuser_name,\n" +
            "\tuser_nickname,\n" +
            "\tpassword,\n" +
            "\tuser_type\n" +
            "FROM\n" +
            "\tusers\n" +
            "WHERE\n" +
            "\tuser_nickname like concat('%',#{keyword},'%')\n" +
            "AND\n" +
            "\tdeleted = 0\n" +
            "LIMIT #{size} OFFSET #{offset}\n")
    List<Users> getUsersByKeyword(String keyword, Long size, Long offset);

    //根据id搜索user
    @Select("SELECT\n" +
            "\tuser_id,\n" +
            "\tuser_name,\n" +
            "\tuser_nickname,\n" +
            "\tpassword\n" +
            "FROM\n" +
            "\tusers\n" +
            "WHERE\n" +
            "\tuser_id = #{userId}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    Users getUserById(Long userId);



    //根据name搜索user
    @Select("SELECT\n" +
            "\tuser_id,\n" +
            "\tuser_name,\n" +
            "\tuser_nickname,\n" +
            "\tpassword\n" +
            "FROM\n" +
            "\tusers\n" +
            "WHERE\n" +
            "\tuser_name = #{userName}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    Users getUserByName(String userName);

}
